// Create center toast

function toastAlert(info){
	var toastCenter = app.toast.create({
		text: info,
		position: 'center',
		closeTimeout: 2000,
	});
	toastCenter.open();
}

//Create center toast
function toastAutoClose(info,closeFunction){
	var toastCenter = app.toast.create({
		text: info,
		position: 'center',
		closeTimeout: 1000,
		on:{
			closed:closeFunction
		}
	});
	toastCenter.open();
}

function toastInfo(info,a){
	var toastCenter = app.toast.create({
		text: info,
		position: 'center',
		closeTimeout: 1000,
		on:{
			closed:a
		}
	});
	toastCenter.open();
}


function isNotEmpty(val){
	
	if(val === undefined){
		return false;
	}
	if(val == "" || val ==null){
	    return false;
	}
	return true;
}

function tojsonarray(){
	var result = [];
	for (i = 0; i < arguments.length; i++)
	{
		result.push(arguments[i]);
	}
	return JSON.stringify(result);
}

Date.prototype.format = function(format) {
    var date = {
           "M+": this.getMonth() + 1,
           "d+": this.getDate(),
           "h+": this.getHours(),
           "m+": this.getMinutes(),
           "s+": this.getSeconds(),
           "q+": Math.floor((this.getMonth() + 3) / 3),
           "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
           format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
           if (new RegExp("(" + k + ")").test(format)) {
                  format = format.replace(RegExp.$1, RegExp.$1.length == 1
                         ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
           }
    }
    return format;
}

String.prototype.startWith=function(str){     
	  var reg=new RegExp("^"+str);     
	  return reg.test(this);        
} 

Array.prototype.contains = function ( needle ) {
  for (i in this) {
    if (this[i] == needle) return true;
  }
  return false;
}

Array.prototype.startWith = function ( needle ) {
  for (i in this) {
	  var reg=new RegExp("^"+this[i]);     
	  if( reg.test(needle)){ return true };
  }
  return false;
}

/**
function setContentHeight(currentUrl){
	if(currentUrl!="/"){
		autoGenPageContentSize(currentUrl);
	}
}
*/

/**
function setPopStyle(popup){
	var winHeight=0;
	var winWidth=0;
	 //获取窗口宽度
    if (window.innerWidth) {
        winWidth = window.innerWidth;
    }
    else if ((document.body) && (document.body.clientWidth)) {
        winWidth = document.body.clientWidth;
    }

    //获取窗口高度
    if (window.innerHeight) {
        winHeight = window.innerHeight;
    } else if ((document.body) && (document.body.clientHeight)){
        winHeight = document.body.clientHeight;
    }

    //通过深入Document内部对body进行检测，获取窗口大小
    if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {

        winHeight=document.documentElement.clientHeight;

        winWidth=document.documentElement.clientWidth;
    }
    
	if(popup.$el.attr("id")=="my-login-screen"){
	    if(winWidth>1024){
	    	$$("#my-login-screen .page-content").css("height",winHeight-20+"px");
	    }
	}
}
*/


function canotHref(info){
	app.dialog.alert(info);
}
function add0(m){return m<10?'0'+m:m }

function dateFormat(shijianchuo)
{
	//shijianchuo是整数，否则要parseInt转换
	var time = new Date(shijianchuo);
	var y = time.getFullYear();
	var m = time.getMonth()+1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}






function JsonObject(){
	return {}; 
}

JsonObject.prototype = {
	constructor:JsonObject,
	toJson:function(){
		return JSON.stringify(this);
	}
}

function toJson(object){
	return JSON.stringify(object);
}

